package com.yunti.business.service.impl;

import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.stream.Collectors;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.service.ISysPostService;
import com.ruoyi.system.service.ISysUserService;
import com.yunti.business.domain.*;
import com.yunti.business.mapper.*;
import com.yunti.business.service.IBaseSubjectService;
import com.yunti.business.service.IOchestrateService;
import com.yunti.business.vo.req.*;
import com.yunti.business.vo.res.*;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xwpf.usermodel.*;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STMerge;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yunti.business.service.IBaseScoreService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import static com.ruoyi.common.core.domain.AjaxResult.DATA_TAG;

/**
 * 学生成绩Service业务层处理
 *
 * @author ruoyi
 * @date 2024-08-22
 */
@Service
public class BaseScoreServiceImpl extends ServiceImpl<BaseScoreMapper, BaseScore> implements IBaseScoreService {

    @Resource
    private IOchestrateService iOchestrateService;

    @Resource
    private IBaseSubjectService baseSubjectService;

    @Autowired
    private BaseScoreMapper baseScoreMapper;

    @Autowired
    private ISysUserService userService;

    @Autowired
    private IOchestrateService orchestrateService;

    @Autowired
    private BaseRaceMapper baseRaceMapper;

    @Autowired
    private BaseSubjectMapper baseSubjectMapper;

    @Autowired
    private BaseSubItemMapper baseSubItemMapper;

    @Autowired
    private BaseScoreRuleMapper baseScoreRuleMapper;

    @Autowired
    private BaseStudentMapper baseStudentMapper;

    @Autowired
    private BaseTeacherMapper baseTeacherMapper;

    @Autowired
    private BaseSchoolMapper baseSchoolMapper;

    @Autowired
    private BaseUnitMapper baseUnitMapper;

    @Autowired
    private OchestrateMapper ochestrateMapper;

    @Autowired
    private RedisCache redisCache;

    @Autowired
    private ISysPostService postService;

    @Autowired
    private WebSocketService webSocketService;


    /**
     * 查询学生成绩
     *
     * @param id 学生成绩主键
     * @return 学生成绩
     */
    @Override
    public BaseScore selectBaseScoreById(Long id) {
        return baseScoreMapper.selectBaseScoreById(id);
    }

    /**
     * 查询学生成绩列表
     *
     * @param baseScore 学生成绩
     * @return 学生成绩
     */
    @Override
    public List<BaseScore> selectBaseScoreList(BaseScore baseScore) {
        return baseScoreMapper.selectBaseScoreList(baseScore);
    }

    /**
     * 新增学生成绩
     *
     * @param baseScore 学生成绩
     * @return 结果
     */
    @Override
    public int insertBaseScore(BaseScore baseScore) {
        baseScore.setCreateTime(LocalDateTime.now());
        return baseScoreMapper.insertBaseScore(baseScore);
    }

    /**
     * 修改学生成绩
     *
     * @param baseScore 学生成绩
     * @return 结果
     */
    @Override
    public int updateBaseScore(BaseScore baseScore) {
        baseScore.setUpdateTime(LocalDateTime.now());
        return baseScoreMapper.updateBaseScore(baseScore);
    }

    /**
     * 批量删除学生成绩
     *
     * @param ids 需要删除的学生成绩主键
     * @return 结果
     */
    @Override
    public int deleteBaseScoreByIds(Long[] ids) {
        return baseScoreMapper.deleteBaseScoreByIds(ids);
    }

    /**
     * 删除学生成绩信息
     *
     * @param id 学生成绩主键
     * @return 结果
     */
    @Override
    public int deleteBaseScoreById(Long id) {
        return baseScoreMapper.deleteBaseScoreById(id);
    }

    @Override
    public TableDataInfo getScoreItem(GetScoreItemReq getScoreItemReq, Integer pageNum, Integer pageSize) {
        List<OrchestrateWithSubRes> orchestrateWithSubResList = new ArrayList<>();
        OrchestrateReq orchestrateReq = new OrchestrateReq();
        orchestrateReq.setSubId(getScoreItemReq.getSubId());
        orchestrateReq.setSchoolId(getScoreItemReq.getSchoolId());
        orchestrateReq.setZb(getScoreItemReq.getZb());
        orchestrateReq.setGroupId(getScoreItemReq.getGroupId());
        TableDataInfo tableDataInfo = iOchestrateService.list(orchestrateReq, pageNum, pageSize);
        List<OrchestrateRes> orchestrateList = new ArrayList<>();
        if (tableDataInfo.getRows() != null && tableDataInfo.getRows().size() > 0) {
            orchestrateList = (List<OrchestrateRes>) tableDataInfo.getRows();
        }
        if (orchestrateList.size() < 0) {
            return tableDataInfo;
        }

        //获取科目
        List<Long> subIdList = orchestrateList.stream().map(OrchestrateRes::getSubId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
        if (subIdList.size() == 0) {
            return tableDataInfo;
        }
        List<SubjectWithItem> subjectWithItemList = baseSubjectService.selectSubjectWithItemByIdList(subIdList);
        Map<Long, SubjectWithItem> subjectWithItemMap = subjectWithItemList.stream().collect(Collectors.toMap(SubjectWithItem::getId, e1 -> e1));

        //获取对象id
        List<Long> studList = orchestrateList.stream().filter(e -> e.getObjectType() == 1).map(OrchestrateRes::getObjectId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
        List<Long> schooldList = orchestrateList.stream().filter(e -> e.getObjectType() == 2).map(OrchestrateRes::getObjectId).filter(Objects::nonNull).distinct().collect(Collectors.toList());

        //获取成绩
        LambdaQueryWrapper<BaseScore> baseScoreLambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (studList.size() > 0) {
            baseScoreLambdaQueryWrapper.and(new Consumer<LambdaQueryWrapper<BaseScore>>() {
                @Override
                public void accept(LambdaQueryWrapper<BaseScore> baseScoreLambdaQueryWrapper) {
                    baseScoreLambdaQueryWrapper.eq(BaseScore::getObjectType, 1);
                    baseScoreLambdaQueryWrapper.in(BaseScore::getObjectId, studList);
                }
            });
        }
        if (schooldList.size() > 0) {
            baseScoreLambdaQueryWrapper.or(new Consumer<LambdaQueryWrapper<BaseScore>>() {
                @Override
                public void accept(LambdaQueryWrapper<BaseScore> baseScoreLambdaQueryWrapper) {
                    baseScoreLambdaQueryWrapper.eq(BaseScore::getObjectType, 2);
                    baseScoreLambdaQueryWrapper.in(BaseScore::getObjectId, schooldList);
                }
            });
        }
        baseScoreLambdaQueryWrapper.eq(BaseScore::getGroupId, getScoreItemReq.getGroupId());
        Map<String, List<BaseScore>> totalBaseScoreMap = new HashMap<>();
        List<BaseScore> baseScoreList = baseScoreMapper.selectList(baseScoreLambdaQueryWrapper);
        for (int i = 0; i < baseScoreList.size(); i++) {
            String key = baseScoreList.get(i).getObjectType() + "-" + baseScoreList.get(i).getObjectId() + "-" + baseScoreList.get(i).getSubId() + "-" + baseScoreList.get(i).getItemNo();
            if (totalBaseScoreMap.get(key) == null) {
                List<BaseScore> newBaseScoreList = new ArrayList<>();
                newBaseScoreList.add(baseScoreList.get(i));
                totalBaseScoreMap.put(key, newBaseScoreList);
            } else {
                List<BaseScore> newBaseScoreList = totalBaseScoreMap.get(key);
                newBaseScoreList.add(baseScoreList.get(i));
                totalBaseScoreMap.put(key, newBaseScoreList);
            }

        }

        for (int i = 0; i < orchestrateList.size(); i++) {
            OrchestrateWithSubRes orchestrateWithSubRes = new OrchestrateWithSubRes();
            BeanUtils.copyProperties(orchestrateList.get(i), orchestrateWithSubRes);
            SubjectWithItem oldSubjectWithItem = subjectWithItemMap.get(orchestrateWithSubRes.getSubId());
            SubjectWithItem newSubjectWithItem = new SubjectWithItem();
            BeanUtils.copyProperties(oldSubjectWithItem, newSubjectWithItem);
            if (newSubjectWithItem != null) {
                Map<Integer, BaseScore> baseScoreMap = new HashMap<>();
                String key = orchestrateList.get(i).getObjectType() + "-" + orchestrateList.get(i).getObjectId() + "-" + orchestrateList.get(i).getSubId() + "-" + "0";

                List<BaseScore> childBaseScoreList = totalBaseScoreMap.get(key);
                if (childBaseScoreList != null && childBaseScoreList.size() > 0) {
                    for (int j = 0; j < childBaseScoreList.size(); j++) {
                        baseScoreMap.put(childBaseScoreList.get(j).getCount().intValue(), childBaseScoreList.get(j));
                    }
                }
                newSubjectWithItem.setBaseScoreMap(baseScoreMap);
            }


            List<BaseSubItemWithScoreRes> newBaseSubItemList = new ArrayList<>();
            List<BaseSubItemWithScoreRes> baseSubItemList = newSubjectWithItem.getBaseSubItemList();
            for (int j = 0; j < baseSubItemList.size(); j++) {
                BaseSubItemWithScoreRes baseSubItemWithScoreRes = new BaseSubItemWithScoreRes();
                BeanUtils.copyProperties(baseSubItemList.get(j), baseSubItemWithScoreRes);
                newBaseSubItemList.add(baseSubItemWithScoreRes);
            }
            for (int j = 0; j < newBaseSubItemList.size(); j++) {
                BaseSubItemWithScoreRes baseSubItemWithScoreRes = newBaseSubItemList.get(j);
                HashMap<Integer, BaseScore> baseScoreMap = new HashMap<>();
                String key = orchestrateList.get(i).getObjectType() + "-" + orchestrateList.get(i).getObjectId() + "-" + orchestrateList.get(i).getSubId() + "-" + baseSubItemWithScoreRes.getItemNo();
                List<BaseScore> childBaseScoreList = totalBaseScoreMap.get(key);
                if (childBaseScoreList != null && childBaseScoreList.size() > 0) {
                    for (int k = 0; k < childBaseScoreList.size(); k++) {
                        baseScoreMap.put(childBaseScoreList.get(k).getCount().intValue(), childBaseScoreList.get(k));
                    }
                }
                baseSubItemWithScoreRes.setScoreHashMap(baseScoreMap);
            }
            newSubjectWithItem.setBaseSubItemList(newBaseSubItemList);
            orchestrateWithSubRes.setSubjectWithItem(newSubjectWithItem);
            orchestrateWithSubResList.add(orchestrateWithSubRes);

        }

        tableDataInfo.setRows(orchestrateWithSubResList);
        return tableDataInfo;

    }

    static List<BigScreenScoreRes> bigScreenScoreResArrayList = new ArrayList<>();

    @Override
    public synchronized AjaxResult updateStuScore(UpdateScoreReq updateScoreReq) {
        if (updateScoreReq.getRawScore() == null) {
            return AjaxResult.error("未提交成绩");
        }
        BigScreenScoreRes bigScreenScoreRes = new BigScreenScoreRes();
        LoginUser loginUser = SecurityUtils.getLoginUser();
        LambdaQueryWrapper<BaseScore> ochestrateLambdaQueryWrapper = new LambdaQueryWrapper<BaseScore>();
        ochestrateLambdaQueryWrapper.eq(BaseScore::getSubId, updateScoreReq.getSubId());
        ochestrateLambdaQueryWrapper.eq(BaseScore::getObjectId, updateScoreReq.getObjectId());
        ochestrateLambdaQueryWrapper.eq(BaseScore::getObjectType, updateScoreReq.getObjectType());
        ochestrateLambdaQueryWrapper.eq(BaseScore::getItemNo, updateScoreReq.getItemNo());
        ochestrateLambdaQueryWrapper.eq(BaseScore::getCount, updateScoreReq.getCount());

        String name = "";
        if (updateScoreReq.getObjectType() == 1) {
            BaseTeacher baseStudent = baseTeacherMapper.selectById(updateScoreReq.getObjectId());
            ochestrateLambdaQueryWrapper.eq(BaseScore::getGroupId, baseStudent.getGroupId());
            name = baseStudent.getTeacherName();
        }
        if (updateScoreReq.getObjectType() == 2) {
            BaseUnit baseSchool = baseUnitMapper.selectById(updateScoreReq.getObjectId());
            name = baseSchool.getUnitName();
            ochestrateLambdaQueryWrapper.eq(BaseScore::getGroupId, updateScoreReq.getGroupId());
        }

        bigScreenScoreRes.setName(name);
        bigScreenScoreRes.setCount(Math.toIntExact(updateScoreReq.getCount()));

        BaseSubject baseSubject = baseSubjectService.selectBaseSubjectById(updateScoreReq.getSubId());
        bigScreenScoreRes.setSubName(baseSubject.getName());
        LambdaQueryWrapper<BaseSubItem> baseSubjectLambdaQueryWrapper = new LambdaQueryWrapper<BaseSubItem>();
        baseSubjectLambdaQueryWrapper.eq(BaseSubItem::getSubId, updateScoreReq.getSubId());
        baseSubjectLambdaQueryWrapper.eq(BaseSubItem::getItemNo, updateScoreReq.getItemNo());
        BaseSubItem baseSubItem = baseSubItemMapper.selectOne(baseSubjectLambdaQueryWrapper);
        bigScreenScoreRes.setSubName2(baseSubItem.getItemName());

        BaseScore baseScore = new BaseScore();
        BeanUtils.copyProperties(updateScoreReq, baseScore);
        if ("ts".equals(baseSubject.getCode())) {
            int count = Integer.parseInt(baseScore.getRawScore());
            double score = 0;
            if (count >= 1000) {
                score = 4;
                score += (count - 1000) * 0.01;
                if (score > 10) {
                    score = 10;
                }
            }
            baseScore.setConversionScore("" + score);
        } else {
            if (baseSubItem.getScoreRuleType() == 0) {
                baseScore.setConversionScore(baseScore.getRawScore());
            } else if (baseSubItem.getScoreRuleType() == -1) {
                if (baseScore.getRawScore().contains("-")) {
                    baseScore.setConversionScore(baseScore.getRawScore());
                } else baseScore.setConversionScore("-" + baseScore.getRawScore());
            } else {
                BaseStudent baseStudent = baseStudentMapper.selectById(updateScoreReq.getObjectId());
                LambdaQueryWrapper<BaseScoreRule> scoreRuleLambdaQueryWrapper = new LambdaQueryWrapper<>();
                scoreRuleLambdaQueryWrapper.eq(BaseScoreRule::getSubItemId, baseSubItem.getId());
                if (NumberUtils.isNumber(updateScoreReq.getRawScore())) {
                    if (baseSubItem.getScoreRuleType() == 2) {
                        scoreRuleLambdaQueryWrapper.le(BaseScoreRule::getRawScore, Double.valueOf(updateScoreReq.getRawScore()));
                    }
                    if (baseSubItem.getScoreRuleType() == 3) {
                        scoreRuleLambdaQueryWrapper.ge(BaseScoreRule::getRawScore, Double.valueOf(updateScoreReq.getRawScore()));
                    }
                }

                scoreRuleLambdaQueryWrapper.orderByDesc(BaseScoreRule::getConvScore);
                scoreRuleLambdaQueryWrapper.last("LIMIT 1");
                scoreRuleLambdaQueryWrapper.and(l -> l.eq(BaseScoreRule::getSexType, 0).or().eq(BaseScoreRule::getSexType, baseStudent.getSex() + 1));
                BaseScoreRule scoreRule = baseScoreRuleMapper.selectOne(scoreRuleLambdaQueryWrapper);
                if ("-1".equals(baseScore.getRawScore()) || "-2".equals(baseScore.getRawScore())) {
                    baseScore.setConversionScore("0");
                } else {
                    baseScore.setConversionScore(scoreRule.getConvScore().toString());
                }

            }
        }

        if (baseScoreMapper.selectList(ochestrateLambdaQueryWrapper).size() > 0) {
            baseScore.setUpdateTime(LocalDateTime.now());
            baseScore.setUpdateBy(loginUser.getUsername());
            baseScoreMapper.update(baseScore, ochestrateLambdaQueryWrapper);
        } else {
            baseScore.setCreateTime(LocalDateTime.now());
            baseScore.setCreateBy(loginUser.getUsername());
            baseScoreMapper.insert(baseScore);
        }
        bigScreenScoreRes.setRawScore(baseScore.getRawScore());
        bigScreenScoreRes.setConvScore(baseScore.getConversionScore());
        bigScreenScoreRes.setTime(LocalDateTime.now() + "");
        bigScreenScoreResArrayList.add(bigScreenScoreRes);
        if (bigScreenScoreResArrayList.size() > 10) {
            bigScreenScoreResArrayList.remove(0);
        }

        //删除小项分
        if (baseScore.getItemNo() == 0) {
            LambdaQueryWrapper<BaseScore> baseScoreLambdaQueryWrapper = new LambdaQueryWrapper<>();
            baseScoreLambdaQueryWrapper.eq(BaseScore::getObjectId, updateScoreReq.getObjectId());
            baseScoreLambdaQueryWrapper.eq(BaseScore::getObjectType, updateScoreReq.getObjectType());
            baseScoreLambdaQueryWrapper.eq(BaseScore::getSubId, updateScoreReq.getSubId());
            baseScoreLambdaQueryWrapper.eq(BaseScore::getCount, updateScoreReq.getCount());
            baseScoreLambdaQueryWrapper.eq(BaseScore::getGroupId, updateScoreReq.getGroupId());
            baseScoreLambdaQueryWrapper.ne(BaseScore::getItemNo, 0);
            baseScoreMapper.delete(baseScoreLambdaQueryWrapper);
        }
        //计算本次总分
        //获取成绩
        LambdaQueryWrapper<BaseScore> baseScoreLambdaQueryWrapper = new LambdaQueryWrapper<>();
        baseScoreLambdaQueryWrapper.eq(BaseScore::getObjectId, updateScoreReq.getObjectId());
        baseScoreLambdaQueryWrapper.eq(BaseScore::getObjectType, updateScoreReq.getObjectType());
        baseScoreLambdaQueryWrapper.eq(BaseScore::getSubId, updateScoreReq.getSubId());
        baseScoreLambdaQueryWrapper.eq(BaseScore::getCount, updateScoreReq.getCount());
        baseScoreLambdaQueryWrapper.eq(BaseScore::getGroupId, updateScoreReq.getGroupId());
        List<BaseScore> oldBaseScoreList = baseScoreMapper.selectList(baseScoreLambdaQueryWrapper);
        {
            boolean hasItemScore = false;

            BaseScore endScore = null;
            BigDecimal endScoreValue = new BigDecimal("0");
            for (int i = 0; i < oldBaseScoreList.size(); i++) {
                if (oldBaseScoreList.get(i).getItemNo() == 0) {
                    endScore = oldBaseScoreList.get(i);
                } else {
                    hasItemScore = true;
                    endScoreValue = endScoreValue.add(new BigDecimal(oldBaseScoreList.get(i).getConversionScore()));
                }
            }
            if (hasItemScore) {
                if (endScore != null) {
                    endScore.setUpdateTime(LocalDateTime.now());
                    endScore.setUpdateBy(loginUser.getUsername());
                    endScore.setConversionScore(endScoreValue.toString());
                    endScore.setRawScore("");
                    baseScoreMapper.updateById(endScore);
                } else {
                    endScore = new BaseScore();
                    endScore.setObjectId(updateScoreReq.getObjectId());
                    endScore.setObjectType(updateScoreReq.getObjectType());
                    endScore.setSubId(updateScoreReq.getSubId());
                    endScore.setCount(updateScoreReq.getCount());
                    endScore.setItemNo(0L);
                    endScore.setGroupId(updateScoreReq.getGroupId());
                    endScore.setCreateTime(LocalDateTime.now());
                    endScore.setCreateBy(loginUser.getUsername());
                    endScore.setConversionScore(endScoreValue.toString());
                    baseScoreMapper.insert(endScore);
                }
            } else {

            }
        }


        //计算多次成绩的最终总分
        LambdaQueryWrapper<BaseScore> finalBaseScoreLambdaQueryWrapper = new LambdaQueryWrapper<>();
        finalBaseScoreLambdaQueryWrapper.eq(BaseScore::getObjectId, updateScoreReq.getObjectId());
        finalBaseScoreLambdaQueryWrapper.eq(BaseScore::getObjectType, updateScoreReq.getObjectType());
        finalBaseScoreLambdaQueryWrapper.eq(BaseScore::getSubId, updateScoreReq.getSubId());
        finalBaseScoreLambdaQueryWrapper.eq(BaseScore::getGroupId, updateScoreReq.getGroupId());
        finalBaseScoreLambdaQueryWrapper.eq(BaseScore::getItemNo, 0);
        List<BaseScore> finalBaseScoreList = baseScoreMapper.selectList(finalBaseScoreLambdaQueryWrapper);

        if (updateScoreReq.getCount() == 0) {
            return AjaxResult.success("操作成功");
        }

        BaseScore finalScore = null;
        BigDecimal finalScoreValue = new BigDecimal("0");
        String finalRawScore = "";

        if (baseSubject.getConvertType() == null || "max".equals(baseSubject.getConvertType())) {
            BigDecimal maxScoreValue = new BigDecimal("0");
            for (int i = 0; i < finalBaseScoreList.size(); i++) {
                if (finalBaseScoreList.get(i).getCount() == 0) {
                    finalScore = finalBaseScoreList.get(i);
                } else {
                    if (finalBaseScoreList.get(i).getConversionScore() != null) {
                        BigDecimal nowScore = new BigDecimal(finalBaseScoreList.get(i).getConversionScore());
                        if (nowScore.compareTo(maxScoreValue) > 0) {
                            maxScoreValue = nowScore;
                            finalRawScore = finalBaseScoreList.get(i).getRawScore();
                        }
                    }
                }
            }
            finalScoreValue = maxScoreValue;
        }
        if (baseSubject.getConvertType() != null && "avg".equals(baseSubject.getConvertType())) {
            BigDecimal avgScoreValue = new BigDecimal("0");
            BigDecimal totalScoreValue = new BigDecimal("0");
            int scoreCount = 0;
            for (int i = 0; i < finalBaseScoreList.size(); i++) {
                if (finalBaseScoreList.get(i).getCount() == 0) {
                    finalScore = finalBaseScoreList.get(i);
                } else {
                    if (finalBaseScoreList.get(i).getConversionScore() != null) {
                        BigDecimal nowScore = new BigDecimal(finalBaseScoreList.get(i).getConversionScore());
                        totalScoreValue = totalScoreValue.add(nowScore);
                        scoreCount++;
                    }
                }
            }
            if (scoreCount > 0) {
                avgScoreValue = totalScoreValue.divide(new BigDecimal(scoreCount), 2, BigDecimal.ROUND_HALF_UP);
                finalScoreValue = avgScoreValue;
            }
        }

        if (finalScore != null) {
            finalScore.setUpdateTime(LocalDateTime.now());
            finalScore.setUpdateBy(loginUser.getUsername());
            finalScore.setConversionScore(finalScoreValue.toString());
            finalScore.setRawScore(finalRawScore);
            baseScoreMapper.updateById(finalScore);
        } else {
            finalScore = new BaseScore();
            finalScore.setObjectId(updateScoreReq.getObjectId());
            finalScore.setObjectType(updateScoreReq.getObjectType());
            finalScore.setSubId(updateScoreReq.getSubId());
            finalScore.setCount(0L);
            finalScore.setItemNo(0L);
            finalScore.setGroupId(updateScoreReq.getGroupId());
            finalScore.setCreateTime(LocalDateTime.now());
            finalScore.setCreateBy(loginUser.getUsername());
            finalScore.setConversionScore(finalScoreValue.toString());
            finalScore.setRawScore(finalRawScore);
            baseScoreMapper.insert(finalScore);
        }

        return AjaxResult.success("操作成功");
    }

    @Override
    public AjaxResult getSchoolScoreList(Long raceId, Long groupId) {
        List<SchoolScoreRes> schoolScoreResList = new ArrayList<>();

        if (raceId == -1) {
            LoginUser loginUser = SecurityUtils.getLoginUser();
            raceId = loginUser.getSelectRaceId();
        }

        List<BaseUnit> baseSchoolList = ochestrateMapper.selectBaseUnitList(null, raceId, null, groupId);


        //获取科目列表
        PageHelper.startPage(1, 1000);
        List<BaseSubject> baseSubjectList = baseSubjectService.selectBaseSubjectList(new BaseSubject());


        //获取对象id
        List<Long> schoolIdList = baseSchoolList.stream().map(BaseUnit::getId).filter(Objects::nonNull).distinct().collect(Collectors.toList());

        LambdaQueryWrapper<BaseTeacher> baseStudentLambdaQueryWrapper = new LambdaQueryWrapper<>();
        baseStudentLambdaQueryWrapper.in(BaseTeacher::getUnitId, schoolIdList);
        List<BaseTeacher> baseStudentList = baseTeacherMapper.selectList(baseStudentLambdaQueryWrapper);
        Map<Long, BaseTeacher> baseStudentMap = baseStudentList.stream().collect(Collectors.toMap(BaseTeacher::getId, e -> e));
        List<Long> studList = baseStudentList.stream().map(BaseTeacher::getId).filter(Objects::nonNull).distinct().collect(Collectors.toList());


        //获取成绩
        LambdaQueryWrapper<BaseScore> baseScoreLambdaQueryWrapper = new LambdaQueryWrapper<>();

        if (studList.size() > 0) {
            baseScoreLambdaQueryWrapper.and(new Consumer<LambdaQueryWrapper<BaseScore>>() {
                @Override
                public void accept(LambdaQueryWrapper<BaseScore> baseScoreLambdaQueryWrapper) {
                    baseScoreLambdaQueryWrapper.eq(BaseScore::getCount, 0);
                    baseScoreLambdaQueryWrapper.eq(BaseScore::getItemNo, 0);
                    baseScoreLambdaQueryWrapper.eq(BaseScore::getObjectType, 1);
                    baseScoreLambdaQueryWrapper.in(BaseScore::getObjectId, studList);
                    baseScoreLambdaQueryWrapper.eq(BaseScore::getGroupId, groupId);
                }
            });
        }

        if (schoolIdList.size() > 0) {
            baseScoreLambdaQueryWrapper.or(new Consumer<LambdaQueryWrapper<BaseScore>>() {
                @Override
                public void accept(LambdaQueryWrapper<BaseScore> baseScoreLambdaQueryWrapper) {
                    baseScoreLambdaQueryWrapper.eq(BaseScore::getCount, 0);
                    baseScoreLambdaQueryWrapper.eq(BaseScore::getItemNo, 0);
                    baseScoreLambdaQueryWrapper.eq(BaseScore::getObjectType, 2);
                    baseScoreLambdaQueryWrapper.in(BaseScore::getObjectId, schoolIdList);
                    baseScoreLambdaQueryWrapper.eq(BaseScore::getGroupId, groupId);
                }
            });
        }


        Map<String, List<BaseScore>> totalBaseScoreMap = new HashMap<>();
        List<BaseScore> baseScoreList = baseScoreMapper.selectList(baseScoreLambdaQueryWrapper);
        for (int i = 0; i < baseScoreList.size(); i++) {
            Long schoolId = 0L;
            if (baseScoreList.get(i).getObjectType() == 1) {
                BaseTeacher baseStudent = baseStudentMap.get(baseScoreList.get(i).getObjectId());
                if (baseStudent != null) {
                    schoolId = baseStudent.getUnitId();
                }
            }
            if (baseScoreList.get(i).getObjectType() == 2) {
                schoolId = baseScoreList.get(i).getObjectId();
            }
            String key = schoolId + "-" + baseScoreList.get(i).getSubId();
            if (totalBaseScoreMap.get(key) == null) {
                List<BaseScore> newBaseScoreList = new ArrayList<>();
                newBaseScoreList.add(baseScoreList.get(i));
                totalBaseScoreMap.put(key, newBaseScoreList);
            } else {
                List<BaseScore> newBaseScoreList = totalBaseScoreMap.get(key);
                newBaseScoreList.add(baseScoreList.get(i));
                totalBaseScoreMap.put(key, newBaseScoreList);
            }
        }

        for (int i = 0; i < baseSchoolList.size(); i++) {
            BaseUnit baseSchool = baseSchoolList.get(i);
            SchoolScoreRes schoolScoreRes = new SchoolScoreRes();
            BeanUtils.copyProperties(baseSchool, schoolScoreRes);
            List<SchoolScoreRes.ScoreItem> scoreItemList = new ArrayList<>();
            for (int j = 0; j < baseSubjectList.size(); j++) {
                BaseSubject baseSubject = baseSubjectList.get(j);
                SchoolScoreRes.ScoreItem scoreItem = new SchoolScoreRes.ScoreItem();
                scoreItem.setParentId(baseSubject.getParentId());
                scoreItem.setSubId(baseSubject.getId());
                scoreItem.setName(baseSubject.getName());
                scoreItem.setType(baseSubject.getType());

                String key = baseSchool.getId() + "-" + baseSubject.getId();
                String log = "";
                BigDecimal score = new BigDecimal("0");
                if (totalBaseScoreMap.get(key) != null) {
                    List<BaseScore> newBaseScoreList = totalBaseScoreMap.get(key);
                    if (baseSubject.getType() == 1) {
                        BigDecimal totalConvScore = new BigDecimal("0");
                        for (int k = 0; k < newBaseScoreList.size(); k++) {
                            BigDecimal convScore = new BigDecimal(0);
                            if (!StringUtils.isEmpty(newBaseScoreList.get(k).getConversionScore())) {
                                convScore = new BigDecimal(newBaseScoreList.get(k).getConversionScore());
                            }
                            log += newBaseScoreList.get(k);
                            totalConvScore = totalConvScore.add(convScore);
                        }

                        String str = baseSubject.getTeamScoreRule();
                        String[] numbers = str.split("/");
                        double result = Double.parseDouble(numbers[0]) / Double.parseDouble(numbers[1]);
                        score = totalConvScore.multiply(new BigDecimal(result));
                        if (baseSchool.getId() == 31L) {
                            System.out.println(31);
                        }
                    }
                    if (baseSubject.getType() == 2) {
                        score = new BigDecimal(newBaseScoreList.get(0).getConversionScore());
                    }

                }
                if (baseSubject.getConvertRate() != null && !"".equals(baseSubject.getConvertRate().trim())) {
//                    double rate = Double.parseDouble();
                    score = score.multiply(new BigDecimal(baseSubject.getConvertRate()));
                }
                scoreItem.setLog(log);
                scoreItem.setScore(score.setScale(4, BigDecimal.ROUND_UP).toString());
                scoreItemList.add(scoreItem);
            }
            List<SchoolScoreRes.ScoreItem> scoreItemTree = buildDeptTreeSelect(scoreItemList);
            BigDecimal totalScore = new BigDecimal("0");
            for (int j = 0; j < scoreItemTree.size(); j++) {
                computeScore(scoreItemTree.get(j));
                totalScore = totalScore.add(new BigDecimal(scoreItemTree.get(j).getScore()));
            }
            schoolScoreRes.setScoreValue(totalScore);
            schoolScoreRes.setScore(totalScore.setScale(3, RoundingMode.HALF_UP).toString());
            schoolScoreRes.setScoreItemList(scoreItemTree);
            schoolScoreRes.setBadgeSrc(baseSchool.getLogoSrc());
            if (groupId == 1) {
                schoolScoreRes.setGroupName("小学组");
            }
            if (groupId == 2) {
                schoolScoreRes.setGroupName("初中组");
            }
            if (groupId == 3) {
                schoolScoreRes.setGroupName("高中组");
            }
            schoolScoreResList.add(schoolScoreRes);
        }
        schoolScoreResList = schoolScoreResList.stream().sorted(new Comparator<SchoolScoreRes>() {
            @Override
            public int compare(SchoolScoreRes o1, SchoolScoreRes o2) {
                return o2.getScoreValue().compareTo(o1.getScoreValue());
            }
        }).collect(Collectors.toList());
        for (int i = 0; i < schoolScoreResList.size(); i++) {
            schoolScoreResList.get(i).setMc(i + 1);
        }
        return AjaxResult.success(schoolScoreResList);
    }

    @Override
    public AjaxResult getStudentScoreList(Long raceId) {
        List<SchoolScoreRes> studentScoreResList = new ArrayList<>();

        LambdaQueryWrapper<BaseStudent> baseStudentLambdaQueryWrapper = new LambdaQueryWrapper<>();
//        baseSchoolLambdaQueryWrapper.eq(BaseSchool::getId,)
        baseStudentLambdaQueryWrapper.eq(BaseStudent::getTwoConfirm, 1);
        if (raceId != null && raceId != -1) {
            baseStudentLambdaQueryWrapper.eq(BaseStudent::getRaceId, raceId);
        } else {
            LoginUser loginUser = SecurityUtils.getLoginUser();
            baseStudentLambdaQueryWrapper.eq(BaseStudent::getRaceId, loginUser.getSelectRaceId());
        }
        //获取学校列表
        PageHelper.startPage(1, 1000);
        List<BaseStudent> baseStudentList = baseStudentMapper.selectList(baseStudentLambdaQueryWrapper);
        Map<Long, BaseStudent> baseStudentMap = baseStudentList.stream().collect(Collectors.toMap(BaseStudent::getId, e -> e));
        Map<Long, List<BaseStudent>> baseStudentListMap = baseStudentList.stream().collect(Collectors.groupingBy(BaseStudent::getSchoolId));
        List<Long> stuIdList = baseStudentList.stream().map(BaseStudent::getId).filter(Objects::nonNull).distinct().collect(Collectors.toList());

        //获取科目列表
        PageHelper.startPage(1, 1000);
        List<BaseSubject> baseSubjectList = baseSubjectService.selectBaseSubjectList(new BaseSubject());


        //获取对象id
        List<Long> schoolIdList = baseStudentList.stream().map(BaseStudent::getSchoolId).filter(Objects::nonNull).distinct().collect(Collectors.toList());


        LambdaQueryWrapper<BaseSchool> baseSchoolLambdaQueryWrapper = new LambdaQueryWrapper<>();
        baseSchoolLambdaQueryWrapper.in(BaseSchool::getId, schoolIdList);
        List<BaseSchool> baseSchoolList = baseSchoolMapper.selectList(baseSchoolLambdaQueryWrapper);
        Map<Long, BaseSchool> baseSchoolMap = baseSchoolList.stream().collect(Collectors.toMap(BaseSchool::getId, e -> e));


        //获取成绩
        LambdaQueryWrapper<BaseScore> baseScoreLambdaQueryWrapper = new LambdaQueryWrapper<>();
        baseScoreLambdaQueryWrapper.eq(BaseScore::getCount, 0);
        baseScoreLambdaQueryWrapper.eq(BaseScore::getItemNo, 0);
        if (stuIdList.size() > 0) {
            baseScoreLambdaQueryWrapper.and(new Consumer<LambdaQueryWrapper<BaseScore>>() {
                @Override
                public void accept(LambdaQueryWrapper<BaseScore> baseScoreLambdaQueryWrapper) {
                    baseScoreLambdaQueryWrapper.eq(BaseScore::getCount, 0);
                    baseScoreLambdaQueryWrapper.eq(BaseScore::getItemNo, 0);
                    baseScoreLambdaQueryWrapper.eq(BaseScore::getObjectType, 1);
                    baseScoreLambdaQueryWrapper.in(BaseScore::getObjectId, stuIdList);
                }
            });
        }

        if (schoolIdList.size() > 0) {
            baseScoreLambdaQueryWrapper.or(new Consumer<LambdaQueryWrapper<BaseScore>>() {
                @Override
                public void accept(LambdaQueryWrapper<BaseScore> baseScoreLambdaQueryWrapper) {
                    baseScoreLambdaQueryWrapper.eq(BaseScore::getCount, 0);
                    baseScoreLambdaQueryWrapper.eq(BaseScore::getItemNo, 0);
                    baseScoreLambdaQueryWrapper.eq(BaseScore::getObjectType, 2);
                    baseScoreLambdaQueryWrapper.in(BaseScore::getObjectId, schoolIdList);
                }
            });
        }


        Map<String, List<BaseScore>> totalBaseScoreMap = new HashMap<>();
        List<BaseScore> baseScoreList = baseScoreMapper.selectList(baseScoreLambdaQueryWrapper);
        for (int i = 0; i < baseScoreList.size(); i++) {
            if (baseScoreList.get(i).getObjectType() == 1) {
                Long stuId = baseScoreList.get(i).getObjectId();
                String key = stuId + "-" + baseScoreList.get(i).getSubId();
                if (totalBaseScoreMap.get(key) == null) {
                    List<BaseScore> newBaseScoreList = new ArrayList<>();
                    newBaseScoreList.add(baseScoreList.get(i));
                    totalBaseScoreMap.put(key, newBaseScoreList);
                } else {
                    List<BaseScore> newBaseScoreList = totalBaseScoreMap.get(key);
                    newBaseScoreList.add(baseScoreList.get(i));
                    totalBaseScoreMap.put(key, newBaseScoreList);
                }
            }
            if (baseScoreList.get(i).getObjectType() == 2) {
                List<BaseStudent> nowBaseStudentList = baseStudentListMap.get(baseScoreList.get(i).getObjectId());
                for (int j = 0; j < nowBaseStudentList.size(); j++) {
                    String key = nowBaseStudentList.get(j).getId() + "-" + baseScoreList.get(i).getSubId();
                    if (totalBaseScoreMap.get(key) == null) {
                        List<BaseScore> newBaseScoreList = new ArrayList<>();
                        newBaseScoreList.add(baseScoreList.get(i));
                        totalBaseScoreMap.put(key, newBaseScoreList);
                    } else {
                        List<BaseScore> newBaseScoreList = totalBaseScoreMap.get(key);
                        newBaseScoreList.add(baseScoreList.get(i));
                        totalBaseScoreMap.put(key, newBaseScoreList);
                    }
                }
            }

        }

        for (int i = 0; i < baseStudentList.size(); i++) {
            BaseStudent baseStudent = baseStudentList.get(i);
            SchoolScoreRes schoolScoreRes = new SchoolScoreRes();
            BeanUtils.copyProperties(baseStudent, schoolScoreRes);
            List<SchoolScoreRes.ScoreItem> scoreItemList = new ArrayList<>();
            for (int j = 0; j < baseSubjectList.size(); j++) {
                BaseSubject baseSubject = baseSubjectList.get(j);
                SchoolScoreRes.ScoreItem scoreItem = new SchoolScoreRes.ScoreItem();
                scoreItem.setParentId(baseSubject.getParentId());
                scoreItem.setSubId(baseSubject.getId());
                scoreItem.setName(baseSubject.getName());
                scoreItem.setType(baseSubject.getType());

                String key = baseStudent.getId() + "-" + baseSubject.getId();
                String log = "";
                BigDecimal score = new BigDecimal("0");
                if (totalBaseScoreMap.get(key) != null) {
                    List<BaseScore> newBaseScoreList = totalBaseScoreMap.get(key);
                    if (baseSubject.getType() == 1 && !StringUtils.isEmpty(newBaseScoreList.get(0).getConversionScore())) {
                        score = new BigDecimal(newBaseScoreList.get(0).getConversionScore());
                    }
                    if (baseSubject.getType() == 2 && !StringUtils.isEmpty(newBaseScoreList.get(0).getConversionScore())) {
                        score = new BigDecimal(newBaseScoreList.get(0).getConversionScore());
                    }

                }
                if (baseSubject.getConvertRate() != null && !"".equals(baseSubject.getConvertRate().trim())) {
                    double rate = Double.parseDouble(baseSubject.getConvertRate());
                    score = score.multiply(new BigDecimal(rate));
                }
                scoreItem.setLog(log);
                scoreItem.setScore(score.setScale(3, BigDecimal.ROUND_UP).toString());
                scoreItemList.add(scoreItem);
            }
            List<SchoolScoreRes.ScoreItem> scoreItemTree = buildDeptTreeSelect(scoreItemList);
            BigDecimal totalScore = new BigDecimal("0");
            for (int j = 0; j < scoreItemTree.size(); j++) {
                computeScore(scoreItemTree.get(j));
                totalScore = totalScore.add(new BigDecimal(scoreItemTree.get(j).getScore()));
            }
            schoolScoreRes.setScoreValue(totalScore);
            schoolScoreRes.setScore(totalScore.setScale(3, RoundingMode.HALF_UP).toString());
            schoolScoreRes.setScoreItemList(scoreItemTree);
            schoolScoreRes.setSex(baseStudent.getSex());
            schoolScoreRes.setUnitName(baseSchoolMap.get(baseStudent.getSchoolId()).getName());
            studentScoreResList.add(schoolScoreRes);
        }
        studentScoreResList = studentScoreResList.stream().sorted(new Comparator<SchoolScoreRes>() {
            @Override
            public int compare(SchoolScoreRes o1, SchoolScoreRes o2) {
                return o2.getScoreValue().compareTo(o1.getScoreValue());
            }
        }).collect(Collectors.toList());
        for (int i = 0; i < studentScoreResList.size(); i++) {
            studentScoreResList.get(i).setMc(i + 1);
        }
        return AjaxResult.success(studentScoreResList);
    }


    public BigDecimal computeScore(SchoolScoreRes.ScoreItem scoreItem) {
        if (scoreItem == null || scoreItem.getChildScoreItemList() == null || scoreItem.getChildScoreItemList().size() == 0) {
            return new BigDecimal(scoreItem.getScore());
        }
        BigDecimal totalScore = new BigDecimal(0);
        for (SchoolScoreRes.ScoreItem child : scoreItem.getChildScoreItemList()) {
            BigDecimal score = computeScore(child);
            totalScore = totalScore.add(score);
        }
        scoreItem.setScore(totalScore.setScale(3, RoundingMode.HALF_UP).toString());
        return new BigDecimal(scoreItem.getScore());
    }

    /**
     * 构建前端所需要下拉树结构
     *
     * @param baseSubjectList 部门列表
     * @return 下拉树结构列表
     */
    public List<SchoolScoreRes.ScoreItem> buildDeptTreeSelect(List<SchoolScoreRes.ScoreItem> baseSubjectList) {
        List<SchoolScoreRes.ScoreItem> deptTrees = buildDeptTree(baseSubjectList);
        return deptTrees;
    }

    public List<SchoolScoreRes.ScoreItem> buildDeptTree(List<SchoolScoreRes.ScoreItem> baseSubjectList) {
        List<SchoolScoreRes.ScoreItem> returnList = new ArrayList<SchoolScoreRes.ScoreItem>();
        List<Long> tempList = baseSubjectList.stream().map(SchoolScoreRes.ScoreItem::getSubId).collect(Collectors.toList());
        for (SchoolScoreRes.ScoreItem baseSubject : baseSubjectList) {
            // 如果是顶级节点, 遍历该父节点的所有子节点
            if (!tempList.contains(baseSubject.getParentId())) {
                recursionFn(baseSubjectList, baseSubject);
                returnList.add(baseSubject);
            }
        }
        if (returnList.isEmpty()) {
            returnList = baseSubjectList;
        }
        return returnList;
    }

    /**
     * 递归列表
     */
    private void recursionFn(List<SchoolScoreRes.ScoreItem> list, SchoolScoreRes.ScoreItem t) {
        // 得到子节点列表
        List<SchoolScoreRes.ScoreItem> childList = getChildList(list, t);
        t.setChildScoreItemList(childList);
        for (SchoolScoreRes.ScoreItem tChild : childList) {
            if (hasChild(list, tChild)) {
                recursionFn(list, tChild);
            }
        }
    }

    /**
     * 得到子节点列表
     */
    private List<SchoolScoreRes.ScoreItem> getChildList(List<SchoolScoreRes.ScoreItem> list, SchoolScoreRes.ScoreItem t) {
        List<SchoolScoreRes.ScoreItem> tlist = new ArrayList<SchoolScoreRes.ScoreItem>();
        Iterator<SchoolScoreRes.ScoreItem> it = list.iterator();
        while (it.hasNext()) {
            SchoolScoreRes.ScoreItem n = (SchoolScoreRes.ScoreItem) it.next();
            if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getSubId().longValue()) {
                tlist.add(n);
            }
        }
        return tlist;
    }

    /**
     * 判断是否有子节点
     */
    private boolean hasChild(List<SchoolScoreRes.ScoreItem> list, SchoolScoreRes.ScoreItem t) {
        return getChildList(list, t).size() > 0;
    }

    @Override
    public void outputShoujiWord(HttpServletResponse response, Long subId) throws IOException {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        Long raceId = loginUser.getSelectRaceId();
        BaseRace baseRace = baseRaceMapper.selectById(raceId);
        BaseSubject baseSubject = baseSubjectMapper.selectById(subId);

        GetScoreItemReq getScoreItemReq = new GetScoreItemReq();
        getScoreItemReq.setSubId(subId);

        List<OrchestrateWithSubRes> orchestrateWithSubResList = (List<OrchestrateWithSubRes>) getScoreItem(getScoreItemReq, 1, 1000).getRows();

        XWPFDocument doc = new XWPFDocument();

        XWPFParagraph paragraph = doc.createParagraph();
        paragraph.setAlignment(ParagraphAlignment.CENTER);
        XWPFRun run = paragraph.createRun();
        run.setText(baseRace.getName());
        run.setFontSize(16); //设置字体大小 14
        run.setFontFamily("等线"); //设置字体为宋体
        run.setBold(true); //设置加粗

        paragraph = doc.createParagraph();
        paragraph.setAlignment(ParagraphAlignment.CENTER);
        run = paragraph.createRun();
        run.setText("手记登分表");
        run.setFontSize(14); //设置字体大小 14
        run.setFontFamily("等线"); //设置字体为宋体
        run.setBold(true); //设置加粗

        paragraph = doc.createParagraph();
        paragraph.setAlignment(ParagraphAlignment.LEFT);
        run = paragraph.createRun();
        run.setText("科目：" + baseSubject.getName());
        run.setFontSize(12); //设置字体大小 14
        run.setFontFamily("等线"); //设置字体为宋体
        run.setBold(true); //设置加粗

        int scoreCount = baseSubject.getCount();
        for (int i = 0; i < orchestrateWithSubResList.size(); i++) {
            OrchestrateWithSubRes orchestrateWithSubRes = orchestrateWithSubResList.get(i);
            paragraph = doc.createParagraph();
            paragraph.setAlignment(ParagraphAlignment.LEFT);
            run = paragraph.createRun();
            run.setText(orchestrateWithSubRes.getName());
            run.setFontSize(12); //设置字体大小 14
            run.setFontFamily("等线"); //设置字体为宋体
            run.setBold(true); //设置加粗

            for (int j = 0; j < scoreCount; j++) {
                paragraph = doc.createParagraph();
                paragraph.setAlignment(ParagraphAlignment.LEFT);
                run = paragraph.createRun();
                run.setText("第" + (j + 1) + "次成绩");
                run.setFontSize(12); //设置字体大小 14
                run.setFontFamily("等线"); //设置字体为宋体
                run.setBold(true); //设置加粗
                run = paragraph.createRun();
                run.setText("\n");

                XWPFTable table = doc.createTable(1, 10);
                table.setTableAlignment(TableRowAlign.CENTER);
                table.setWidth("10000");
                table.getRow(0).getCell(0).setText("名称");
                table.getRow(0).getCell(0).setWidth("10%");

                table.getRow(0).getCell(1).setWidth("10%");
                table.getRow(0).getCell(1).setText(orchestrateWithSubRes.getName());
                table.getRow(0).getCell(1).setWidth("10%");


                table.getRow(0).getCell(2).setWidth("10%");

                table.getRow(0).getCell(3).setText("单位");
                table.getRow(0).getCell(3).setWidth("10%");

                table.getRow(0).getCell(4).setText(orchestrateWithSubRes.getUnitName() + "");
                table.getRow(0).getCell(4).setWidth("10%");

                table.getRow(0).getCell(5).setWidth("10%");
                table.getRow(0).getCell(6).setWidth("10%");
                table.getRow(0).getCell(6).setText("赛中编号");

                table.getRow(0).getCell(7).setText(orchestrateWithSubRes.getNo() + "");
                table.getRow(0).getCell(7).setWidth("10%");
                table.getRow(0).getCell(8).setText("最终成绩");
                table.getRow(0).getCell(8).setWidth("10%");
                table.getRow(0).getCell(9).setWidth("10%");

                table.getRow(0).getCell(1).getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.RESTART);
                table.getRow(0).getCell(2).getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.CONTINUE);
                table.getRow(0).getCell(1).setWidth("20%");
                table.getRow(0).getCell(4).getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.RESTART);
                table.getRow(0).getCell(5).getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.CONTINUE);
                table.getRow(0).getCell(4).setWidth("20%");


                table = doc.createTable(1 + orchestrateWithSubRes.getSubjectWithItem().getBaseSubItemList().size(), 10);
                table.getRow(0).getCell(0).setText("成绩项");
                table.getRow(0).getCell(2).setText("原始成绩");
                table.getRow(0).getCell(4).setText("换算成绩");
                for (int k = 0; k < orchestrateWithSubRes.getSubjectWithItem().getBaseSubItemList().size() + 1; k++) {
                    table.getRow(k).getCell(0).getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.RESTART);
                    table.getRow(k).getCell(1).getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.CONTINUE);
                    table.getRow(k).getCell(0).setWidth("20%");
                    table.getRow(k).getCell(2).getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.RESTART);
                    table.getRow(k).getCell(3).getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.CONTINUE);
                    table.getRow(k).getCell(2).setWidth("20%");
                    table.getRow(k).getCell(4).getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.RESTART);
                    table.getRow(k).getCell(5).getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.CONTINUE);
                    table.getRow(k).getCell(4).setWidth("20%");
                    table.getRow(k).getCell(6).getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.RESTART);
                    table.getRow(k).getCell(7).getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.CONTINUE);
                    table.getRow(k).getCell(6).setWidth("20%");
                    table.getRow(k).getCell(8).getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.RESTART);
                    table.getRow(k).getCell(9).getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.CONTINUE);
                    table.getRow(k).getCell(8).setWidth("20%");
                }


                for (int k = 0; k < orchestrateWithSubRes.getSubjectWithItem().getBaseSubItemList().size(); k++) {
                    BaseSubItemWithScoreRes baseSubItemWithScoreRes = orchestrateWithSubRes.getSubjectWithItem().getBaseSubItemList().get(k);
                    table.getRow(k + 1).getCell(0).setText(baseSubItemWithScoreRes.getItemName());


//                    table.getRow(k).getCell(1).setWidth("10%");
//                    table.getRow(k).getCell(1).setText("成绩项");
//                    table.getRow(k).getCell(2).setWidth("10%");
//                    table.getRow(k).getCell(3).setWidth("10%");
//                    table.getRow(k).getCell(3).setText("原始成绩");
//                    table.getRow(k).getCell(4).setWidth("10%");
//                    table.getRow(k).getCell(5).setWidth("10%");
//                    table.getRow(k).getCell(5).setText("换算成绩");
//                    table.getRow(k).getCell(6).setWidth("10%");
//                    table.getRow(k).getCell(7).setWidth("10%");
//                    table.getRow(k).getCell(8).setWidth("20%");
                }

                // 遍历表格的每一行
                for (int row = 0; row < table.getNumberOfRows(); row++) {
                    // 遍历每一行的每一列
                    for (int col = 0; col < table.getRow(row).getTableCells().size(); col++) {
                        XWPFTableCell cell = table.getRow(row).getCell(col);
                        cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
                        XWPFParagraph paragraph1 = cell.getParagraphArray(0);
                        if (paragraph1 != null) {
                            paragraph1.setAlignment(ParagraphAlignment.CENTER);//水平居中对齐
                        }
                    }
                    table.getRow(row).setHeight(400); //设置高度
                }
                paragraph = doc.createParagraph();
                paragraph.setAlignment(ParagraphAlignment.LEFT);
                run = paragraph.createRun();
                run.setText("\n");
            }
            paragraph = doc.createParagraph();
            paragraph.setAlignment(ParagraphAlignment.LEFT);
            run = paragraph.createRun();
            run.setText("\n");
            paragraph = doc.createParagraph();
            paragraph.setAlignment(ParagraphAlignment.LEFT);
            run = paragraph.createRun();
            run.setText("\n");
        }


        // 导出Excel文件
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setCharacterEncoding("utf-8");
        doc.write(response.getOutputStream());

    }

    @Override
    public AjaxResult outputScoreWord(HttpServletResponse response, Long subId, Boolean hasName, Long groupId) throws IOException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日HH时mm分");
        LoginUser loginUser = SecurityUtils.getLoginUser();
        Long raceId = loginUser.getSelectRaceId();
        BaseRace baseRace = baseRaceMapper.selectById(raceId);
        BaseSubject baseSubject = baseSubjectMapper.selectById(subId);
        List<BaseSubject> baseSubjectList = new ArrayList<>();
        if (baseSubject.getLottery() == 1) {
            LambdaQueryWrapper<BaseSubject> baseSubjectLambdaQueryWrapper = new LambdaQueryWrapper<>();
            baseSubjectLambdaQueryWrapper.eq(BaseSubject::getParentId, subId);
            baseSubjectList = baseSubjectMapper.selectList(baseSubjectLambdaQueryWrapper);
        }
        Map<Long, BaseSubject> baseSubjectMap = baseSubjectList.stream().collect(Collectors.toMap(BaseSubject::getId, e1 -> e1));

        OrchestrateReq orchestrateReq = new OrchestrateReq();
        orchestrateReq.setSubId(subId);
        orchestrateReq.setGroupId(groupId);
        TableDataInfo tableDataInfo = orchestrateService.list(orchestrateReq, 1, 1000);

        List<OrchestrateRes> orchestrateList = (List<OrchestrateRes>) tableDataInfo.getRows();
        XWPFDocument doc = new XWPFDocument();

        XWPFParagraph paragraph = doc.createParagraph();
        paragraph.setAlignment(ParagraphAlignment.CENTER);
        XWPFRun run = paragraph.createRun();
        run.setText(baseRace.getName());
        run.setFontSize(16); //设置字体大小 14
        run.setFontFamily("等线"); //设置字体为宋体
        run.setBold(true); //设置加粗

        paragraph = doc.createParagraph();
        paragraph.setAlignment(ParagraphAlignment.CENTER);
        run = paragraph.createRun();
        run.setText("成 绩 表");
        run.setFontSize(14); //设置字体大小 14
        run.setFontFamily("等线"); //设置字体为宋体
        run.setBold(true); //设置加粗

        paragraph = doc.createParagraph();
        paragraph.setAlignment(ParagraphAlignment.LEFT);
        run = paragraph.createRun();
        run.setText("科目：" + baseSubject.getName());
        run.setFontSize(12); //设置字体大小 14
        run.setFontFamily("等线"); //设置字体为宋体
        run.setBold(true); //设置加粗

        paragraph = doc.createParagraph();
        paragraph.setAlignment(ParagraphAlignment.LEFT);
        run = paragraph.createRun();
        run.setText("公布时间：" + sdf.format(new Date()));
        run.setFontSize(12); //设置字体大小 14
        run.setFontFamily("等线"); //设置字体为宋体
        run.setBold(true); //设置加粗


        LambdaQueryWrapper<BaseScore> baseScoreLambdaQueryWrapper = new LambdaQueryWrapper<>();
        baseScoreLambdaQueryWrapper.eq(BaseScore::getSubId, baseSubject.getId());
        baseScoreLambdaQueryWrapper.eq(BaseScore::getCount, 0);
        baseScoreLambdaQueryWrapper.eq(BaseScore::getItemNo, 0);
        baseScoreLambdaQueryWrapper.eq(BaseScore::getGroupId, groupId);
        List<Long> studList = orchestrateList.stream().filter(e -> e.getObjectType() == 1).map(Ochestrate::getObjectId).collect(Collectors.toList());
        List<Long> schoolIdList = orchestrateList.stream().filter(e -> e.getObjectType() == 2).map(Ochestrate::getObjectId).collect(Collectors.toList());


        Map<Long, List<BaseTeacher>> baseStudentMap = new HashMap<>();

        if (studList.size() > 0) {
            baseScoreLambdaQueryWrapper.and(new Consumer<LambdaQueryWrapper<BaseScore>>() {
                @Override
                public void accept(LambdaQueryWrapper<BaseScore> baseScoreLambdaQueryWrapper) {
                    baseScoreLambdaQueryWrapper.eq(BaseScore::getCount, 0);
                    baseScoreLambdaQueryWrapper.eq(BaseScore::getItemNo, 0);
                    baseScoreLambdaQueryWrapper.eq(BaseScore::getObjectType, 1);
                    baseScoreLambdaQueryWrapper.in(BaseScore::getObjectId, studList);
                    baseScoreLambdaQueryWrapper.eq(BaseScore::getGroupId, groupId);
                }
            });
        }

        if (schoolIdList.size() > 0) {
            baseScoreLambdaQueryWrapper.or(new Consumer<LambdaQueryWrapper<BaseScore>>() {
                @Override
                public void accept(LambdaQueryWrapper<BaseScore> baseScoreLambdaQueryWrapper) {
                    baseScoreLambdaQueryWrapper.eq(BaseScore::getCount, 0);
                    baseScoreLambdaQueryWrapper.eq(BaseScore::getItemNo, 0);
                    baseScoreLambdaQueryWrapper.eq(BaseScore::getObjectType, 2);
                    baseScoreLambdaQueryWrapper.in(BaseScore::getObjectId, schoolIdList);
                    baseScoreLambdaQueryWrapper.eq(BaseScore::getGroupId, groupId);
                }
            });
        }
        List<BaseScore> baseScoreList = baseScoreMapper.selectList(baseScoreLambdaQueryWrapper);

        Map<String, BaseScore> totalBaseScoreMap = new HashMap<>();
        for (int i = 0; i < baseScoreList.size(); i++) {
            String key = baseScoreList.get(i).getObjectType() + baseScoreList.get(i).getObjectId() + "-" + baseScoreList.get(i).getSubId();
            totalBaseScoreMap.put(key, baseScoreList.get(i));
        }

        int width = 7;
        if (hasName) {
            width++;
        }
        XWPFTable table = doc.createTable(orchestrateList.size() + 1, width);
        table.setTableAlignment(TableRowAlign.CENTER);

        table.setWidth("10000");

        int index = 0;

        table.getRow(0).getCell(index).setText("出场序号");
        table.getRow(0).getCell(index).setWidth("5%");

        index++;
        table.getRow(0).getCell(index).setText("组别");
        table.getRow(0).getCell(index).setWidth("10%");

        if (hasName) {
            index++;
            table.getRow(0).getCell(index).setText("单位");
            table.getRow(0).getCell(index).setWidth("10%");

            if (baseSubject.getType() == 1) {
                index++;
                table.getRow(0).getCell(index).setText("姓名");
                table.getRow(0).getCell(index).setWidth("20%");
            }
            if (baseSubject.getType() == 2) {
                LambdaQueryWrapper<BaseTeacher> baseStudentLambdaQueryWrapper = new LambdaQueryWrapper<>();
                baseStudentLambdaQueryWrapper.eq(BaseTeacher::getGroupId, orchestrateReq.getGroupId());
                baseStudentLambdaQueryWrapper.in(BaseTeacher::getUnitId, schoolIdList);
                List<BaseTeacher> baseStudentList = baseTeacherMapper.selectList(baseStudentLambdaQueryWrapper);
                System.out.println(baseStudentList);
                baseStudentMap = baseStudentList.stream().collect(Collectors.groupingBy(BaseTeacher::getUnitId));

                index++;
                table.getRow(0).getCell(index).setText("成员");
                table.getRow(0).getCell(index).setWidth("20%");
            }

        }

        index++;
        table.getRow(0).getCell(index).setText("成绩");
        table.getRow(0).getCell(index).setWidth("10%");

        index++;
        table.getRow(0).getCell(index).setText("得分");
        table.getRow(0).getCell(index).setWidth("10%");


        index++;
        table.getRow(0).getCell(index).setText("名次");
        table.getRow(0).getCell(index).setWidth("5%");

        index++;
        table.getRow(0).getCell(index).setText("备注");
        table.getRow(0).getCell(index).setWidth("10%");

        for (int i = 0; i < orchestrateList.size(); i++) {
            OrchestrateRes orchestrateRes = orchestrateList.get(i);
            String key = orchestrateRes.getObjectType() + orchestrateRes.getObjectId() + "-" + baseSubject.getId();
            if (totalBaseScoreMap.get(key) != null) {
                BaseScore baseScore = totalBaseScoreMap.get(key);
                orchestrateRes.setConversionScore(baseScore.getConversionScore());
            }
        }
        orchestrateList = orchestrateList.stream().sorted(new Comparator<OrchestrateRes>() {
            @Override
            public int compare(OrchestrateRes o1, OrchestrateRes o2) {
                BigDecimal o1Score = BigDecimal.ZERO;
                BigDecimal o2Score = BigDecimal.ZERO;
                if (o1.getConversionScore() != null) {
                    o1Score = new BigDecimal(o1.getConversionScore());
                }
                if (o2.getConversionScore() != null) {
                    o2Score = new BigDecimal(o2.getConversionScore());
                }
                return o2Score.compareTo(o1Score);
            }
        }).collect(Collectors.toList());

        int startMc = 0;
        for (int i = 0; i < orchestrateList.size(); i++) {
            if (orchestrateList.get(i).getConversionScore() != null) {
                if (i == 0) {
                    orchestrateList.get(i).setMc(i + 1 + "");
                } else {
                    if (orchestrateList.get(i).getConversionScore().equals(orchestrateList.get(i - 1).getConversionScore())) {
                        orchestrateList.get(i).setMc(orchestrateList.get(i - 1).getMc());
                    } else {
                        orchestrateList.get(i).setMc(i + 1 + "");
                    }
                }

            }

        }
        for (int i = 0; i < orchestrateList.size(); i++) {
            OrchestrateRes orchestrateRes = orchestrateList.get(i);
            index = 0;
            //第一行数据
            table.getRow(i + 1).getCell(index).setText(orchestrateRes.getNo() + "");
            table.getRow(i + 1).getCell(index).setWidth("5%");

            index++;
            table.getRow(i + 1).getCell(index).setText(orchestrateRes.getGroupName() + "");
            table.getRow(i + 1).getCell(index).setWidth("10%");

            if (hasName) {
                index++;
                table.getRow(i + 1).getCell(index).setText(orchestrateRes.getUnitName() + "");
                table.getRow(i + 1).getCell(index).setWidth("10%");

                if (baseSubject.getType() == 1) {
                    index++;
                    table.getRow(i + 1).getCell(index).setText(orchestrateRes.getName() + "");
                    table.getRow(i + 1).getCell(index).setWidth("20%");
                }
                if (baseSubject.getType() == 2) {
                    index++;
                    List<BaseTeacher> baseStudentList = baseStudentMap.get(orchestrateRes.getObjectId());
                    String members = "";
                    for (int j = 0; j < baseStudentList.size(); j++) {
                        members += (baseStudentList.get(j).getTeacherName());
                        if (j < baseStudentList.size() - 1) {
                            members += "、";
                        }
                    }
                    table.getRow(i + 1).getCell(index).setText(members);
                    table.getRow(i + 1).getCell(index).setWidth("20%");
                }


            }


            String key = orchestrateRes.getObjectType() + orchestrateRes.getObjectId() + "-" + baseSubject.getId();
            if (totalBaseScoreMap.get(key) != null) {
                BaseScore baseScore = totalBaseScoreMap.get(key);
                index++;
                table.getRow(i + 1).getCell(index).setText(baseScore.getRawScore() + "");
                table.getRow(i + 1).getCell(index).setWidth("10%");
                index++;
                table.getRow(i + 1).getCell(index).setText(baseScore.getConversionScore() + "");
                table.getRow(i + 1).getCell(index).setWidth("10%");
            } else {
                index++;
                table.getRow(i + 1).getCell(index).setWidth("10%");
                index++;
                table.getRow(i + 1).getCell(index).setWidth("10%");
            }
            index++;
            table.getRow(i + 1).getCell(index).setText(orchestrateRes.getMc() == null ? "" : orchestrateRes.getMc() + "");
            table.getRow(i + 1).getCell(index).setWidth("5%");

            index++;
            table.getRow(i + 1).getCell(index).setText("");
            table.getRow(i + 1).getCell(index).setWidth("10%");

        }

        // 遍历表格的每一行
        for (int row = 0; row < table.getNumberOfRows(); row++) {
            // 遍历每一行的每一列
            for (int col = 0; col < table.getRow(row).getTableCells().size(); col++) {
                XWPFTableCell cell = table.getRow(row).getCell(col);
                cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
                XWPFParagraph paragraph1 = cell.getParagraphArray(0);
                if (paragraph1 != null) {
                    paragraph1.setAlignment(ParagraphAlignment.CENTER);//水平居中对齐
                }
            }
            table.getRow(row).setHeight(400); //设置高度
        }

        paragraph = doc.createParagraph();
        paragraph.setAlignment(ParagraphAlignment.RIGHT);
        run = paragraph.createRun();
        run.setText("总裁判长签字：                                          ");
        run.setFontSize(12); //设置字体大小 14
        run.setFontFamily("等线"); //设置字体为宋体
        run.setBold(true); //设置加粗

        paragraph = doc.createParagraph();
        paragraph.setAlignment(ParagraphAlignment.RIGHT);
        run = paragraph.createRun();
        run.setText("云南省学校体育教学指导委员会");
        run.setFontSize(12); //设置字体大小 14
        run.setFontFamily("等线"); //设置字体为宋体
        run.setBold(true); //设置加粗


        // 导出Excel文件
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setCharacterEncoding("utf-8");
        doc.write(response.getOutputStream());
        return null;
    }


    @Override
    public AjaxResult outputShoujiWord2(HttpServletResponse response, Long subId, Long groupId) throws IOException {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        Long raceId = loginUser.getSelectRaceId();
        BaseRace baseRace = baseRaceMapper.selectById(raceId);
        BaseSubject baseSubject = baseSubjectMapper.selectById(subId);
        List<BaseSubject> baseSubjectList = new ArrayList<>();
        if (baseSubject.getLottery() == 1) {
            LambdaQueryWrapper<BaseSubject> baseSubjectLambdaQueryWrapper = new LambdaQueryWrapper<>();
            baseSubjectLambdaQueryWrapper.eq(BaseSubject::getParentId, subId);
            baseSubjectList = baseSubjectMapper.selectList(baseSubjectLambdaQueryWrapper);
        }
        Map<Long, BaseSubject> baseSubjectMap = baseSubjectList.stream().collect(Collectors.toMap(BaseSubject::getId, e1 -> e1));

        OrchestrateReq orchestrateReq = new OrchestrateReq();
        orchestrateReq.setSubId(subId);
        orchestrateReq.setGroupId(groupId);
        TableDataInfo tableDataInfo = orchestrateService.list(orchestrateReq, 1, 1000);

        List<OrchestrateRes> totalOrchestrateList = (List<OrchestrateRes>) tableDataInfo.getRows();
        XWPFDocument doc = new XWPFDocument();

        XWPFParagraph paragraph = doc.createParagraph();
        paragraph.setAlignment(ParagraphAlignment.CENTER);
        XWPFRun run = paragraph.createRun();
        run.setText(baseRace.getName());
        run.setFontSize(16); //设置字体大小 14
        run.setFontFamily("等线"); //设置字体为宋体
        run.setBold(true); //设置加粗

        paragraph = doc.createParagraph();
        paragraph.setAlignment(ParagraphAlignment.CENTER);
        run = paragraph.createRun();
        run.setText("手 记 表");
        run.setFontSize(14); //设置字体大小 14
        run.setFontFamily("等线"); //设置字体为宋体
        run.setBold(true); //设置加粗

        paragraph = doc.createParagraph();
        paragraph.setAlignment(ParagraphAlignment.LEFT);
        run = paragraph.createRun();
        run.setText("科目：" + baseSubject.getName());
        run.setFontSize(12); //设置字体大小 14
        run.setFontFamily("等线"); //设置字体为宋体
        run.setBold(true); //设置加粗

        for (int i = 0; i < totalOrchestrateList.size(); i++) {
            if (totalOrchestrateList.get(i).getZb() == null) {
                totalOrchestrateList.get(i).setZb(-1);
            }
        }

        //分组
        Map<Integer, List<OrchestrateRes>> orchestrateResMap = totalOrchestrateList.stream().collect(Collectors.groupingBy(Ochestrate::getZb));
        for (Integer zb : orchestrateResMap.keySet()) {
            List<OrchestrateRes> orchestrateList = orchestrateResMap.get(zb);
            int width = 6;
            if (zb != -1) {
                paragraph = doc.createParagraph();
                paragraph.setAlignment(ParagraphAlignment.LEFT);
                run = paragraph.createRun();
                run.setText("第" + zb + "组");
                run.setFontSize(12); //设置字体大小 14
                run.setFontFamily("等线"); //设置字体为宋体
                run.setBold(true); //设置加粗
            } else {
                paragraph = doc.createParagraph();
                paragraph.setAlignment(ParagraphAlignment.LEFT);
                run = paragraph.createRun();
                run.setText("");
                run.setFontSize(12); //设置字体大小 14
                run.setFontFamily("等线"); //设置字体为宋体
                run.setBold(true); //设置加粗
            }
            if ("pdjx".equals(baseSubject.getCode())) {
                width += 3;
            }

            XWPFTable table = doc.createTable(orchestrateList.size() + 1, width);
            table.setTableAlignment(TableRowAlign.CENTER);

            table.setWidth("10000");

            int index = 0;
            //第一行数据
            table.getRow(0).getCell(index).setText("ID号");
            table.getRow(0).getCell(index).setWidth("10%");

            index++;
            table.getRow(0).getCell(index).setText("出场序号");
            table.getRow(0).getCell(index).setWidth("10%");

            if ("pdjx".equals(baseSubject.getCode())) {
                index++;
                table.getRow(0).getCell(index).setText("题目");
                table.getRow(0).getCell(index).setWidth("10%");
            }

            if ("pdjx".equals(baseSubject.getCode())) {
                index++;
                table.getRow(0).getCell(index).setText("成绩1");
                table.getRow(0).getCell(index).setWidth("10%");
            } else {
                index++;
                table.getRow(0).getCell(index).setText("成绩");
                table.getRow(0).getCell(index).setWidth("10%");
            }

            if ("pdjx".equals(baseSubject.getCode())) {
                index++;
                table.getRow(0).getCell(index).setText("成绩2");
                table.getRow(0).getCell(index).setWidth("10%");
            }

            if ("pdjx".equals(baseSubject.getCode())) {
                index++;
                table.getRow(0).getCell(index).setText("成绩3");
                table.getRow(0).getCell(index).setWidth("10%");
            }

            if ("pdjx".equals(baseSubject.getCode())) {
                index++;
                table.getRow(0).getCell(index).setText("最终成绩");
                table.getRow(0).getCell(index).setWidth("10%");
            } else {
                index++;
                table.getRow(0).getCell(index).setText("得分");
                table.getRow(0).getCell(index).setWidth("10%");
            }


            index++;
            table.getRow(0).getCell(index).setText("名次");
            table.getRow(0).getCell(index).setWidth("10%");

            index++;
            table.getRow(0).getCell(index).setText("备注");
            table.getRow(0).getCell(index).setWidth("10%");


            for (int i = 0; i < orchestrateList.size(); i++) {
                OrchestrateRes orchestrateRes = orchestrateList.get(i);
                index = 0;
                //第一行数据
                table.getRow(i + 1).getCell(index).setText(orchestrateRes.getObjectId() + "");
                table.getRow(i + 1).getCell(index).setWidth("10%");

                index++;
                table.getRow(i + 1).getCell(index).setText(orchestrateRes.getNo() + "");
                table.getRow(i + 1).getCell(index).setWidth("10%");

                if ("pdjx".equals(baseSubject.getCode())) {
                    index++;
                    table.getRow(i + 1).getCell(index).setWidth("10%");
                    index++;
                    table.getRow(i + 1).getCell(index).setWidth("10%");
                    index++;
                    table.getRow(i + 1).getCell(index).setWidth("10%");
                }

                index++;
                table.getRow(i + 1).getCell(index).setWidth("10%");
                index++;
                table.getRow(i + 1).getCell(index).setWidth("10%");

                index++;
                table.getRow(i + 1).getCell(index).setText("");
                table.getRow(i + 1).getCell(index).setWidth("10%");

                index++;
                table.getRow(i + 1).getCell(index).setText("");
                table.getRow(i + 1).getCell(index).setWidth("10%");

            }

            // 遍历表格的每一行
            for (int row = 0; row < table.getNumberOfRows(); row++) {
                // 遍历每一行的每一列
                for (int col = 0; col < table.getRow(row).getTableCells().size(); col++) {
                    XWPFTableCell cell = table.getRow(row).getCell(col);
                    cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
                    XWPFParagraph paragraph1 = cell.getParagraphArray(0);
                    if (paragraph1 != null) {
                        paragraph1.setAlignment(ParagraphAlignment.CENTER);//水平居中对齐
                    }
                }
                table.getRow(row).setHeight(400); //设置高度
            }


            paragraph = doc.createParagraph();
            paragraph.setAlignment(ParagraphAlignment.RIGHT);
            run = paragraph.createRun();
            run.setText("裁判长签字：                                        ");
            run.setFontSize(12); //设置字体大小 14
            run.setFontFamily("等线"); //设置字体为宋体
            run.setBold(true); //设置加粗
        }


        // 导出Excel文件
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setCharacterEncoding("utf-8");
        doc.write(response.getOutputStream());
        return null;
    }


    @Override
    public AjaxResult showStuScore(ShowStuInfoReq showStuInfoReq) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        //获取同一个点位的账号
        SysUser sysUser = new SysUser();
        sysUser.setDeptId(loginUser.getDeptId());
        List<SysUser> sysUsers = userService.selectUserList(sysUser);
        LambdaQueryWrapper<BaseScore> baseScoreLambdaQueryWrapper = new LambdaQueryWrapper<>();
        baseScoreLambdaQueryWrapper.eq(BaseScore::getCount, 0);
        baseScoreLambdaQueryWrapper.eq(BaseScore::getItemNo, 0);
        baseScoreLambdaQueryWrapper.eq(BaseScore::getSubId, showStuInfoReq.getSubId());
        baseScoreLambdaQueryWrapper.eq(BaseScore::getObjectType, showStuInfoReq.getObjectType());
        baseScoreLambdaQueryWrapper.eq(BaseScore::getObjectId, showStuInfoReq.getObjectId());
        baseScoreLambdaQueryWrapper.eq(BaseScore::getGroupId, showStuInfoReq.getGroupId());
        BaseScore baseScore = baseScoreMapper.selectOne(baseScoreLambdaQueryWrapper);
        for (int i = 0; i < sysUsers.size(); i++) {
            List<Long> postIds = postService.selectPostListByUserId(sysUsers.get(i).getUserId());
            if (postIds.contains(15L)) {
                WsMessage wsMessage = new WsMessage();
                wsMessage.setSendId(sysUser.getUserId() + "");
                wsMessage.setAcceptId(sysUsers.get(i).getUserId() + "");
                wsMessage.setType("stuScore");

                showStuInfoReq.setType("stuScore");
                if (baseScore != null) {
                    showStuInfoReq.setScore(baseScore.getConversionScore());
                }

                wsMessage.setMessage(JSON.toJSONString(showStuInfoReq));
                webSocketService.sendInfo(wsMessage);
            }
        }
        WsMessage wsMessage = new WsMessage();
        wsMessage.setSendId(sysUser.getUserId() + "");
        wsMessage.setAcceptId(loginUser.getUserId() + "");
        wsMessage.setType("stuScore");

        showStuInfoReq.setType("stuScore");
        if (baseScore != null) {
            showStuInfoReq.setScore(baseScore.getConversionScore());
            baseScore.setConfirm(true);
            updateById(baseScore);
        }

        wsMessage.setMessage(JSON.toJSONString(showStuInfoReq));
        webSocketService.sendInfo(wsMessage);
        return AjaxResult.success();
    }

    @Override
    public AjaxResult stuReady(OrchestrateRes orchestrateRes) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        redisCache.setCacheObject("selectAthlete:" + loginUser.getUserId(), JSON.toJSONString(orchestrateRes), 1, TimeUnit.DAYS);
        //获取同一个点位的账号
        SysUser sysUser = new SysUser();
        sysUser.setDeptId(loginUser.getDeptId());
        List<SysUser> sysUsers = userService.selectUserList(sysUser);

        //发送打分设备
        for (int i = 0; i < sysUsers.size(); i++) {
            WsMessage wsMessage = new WsMessage();
            wsMessage.setSendId(sysUser.getUserId() + "");
            wsMessage.setAcceptId(sysUsers.get(i).getUserId() + "");
            wsMessage.setType("refresh");
            wsMessage.setMessage("refresh");
            webSocketService.sendInfo(wsMessage);
        }

//        //发送显示设备
//        for (int i = 0; i < sysUsers.size(); i++) {
//            List<Long> postIds = postService.selectPostListByUserId(sysUsers.get(i).getUserId());
//            if (postIds.contains(15L)) {
//                WsMessage wsMessage = new WsMessage();
//                wsMessage.setSendId(sysUser.getUserId() + "");
//                wsMessage.setAcceptId(sysUsers.get(i).getUserId() + "");
//                wsMessage.setType("stuReady");
//
//                ShowStuInfoReq showStuInfoReq = new ShowStuInfoReq();
//                showStuInfoReq.setNo(orchestrateRes.getNo() + "");
//                showStuInfoReq.setSubName(orchestrateRes.getSubName());
//                showStuInfoReq.setType("stuReady");
//                wsMessage.setMessage(JSON.toJSONString(showStuInfoReq));
//                webSocketService.sendInfo(wsMessage);
//            }
//        }

        WsMessage wsMessage = new WsMessage();
        wsMessage.setSendId(sysUser.getUserId() + "");
        wsMessage.setAcceptId(loginUser.getUserId() + "");
        wsMessage.setType("stuReady");

        ShowStuInfoReq showStuInfoReq = new ShowStuInfoReq();
        showStuInfoReq.setNo(orchestrateRes.getNo() + "");
        showStuInfoReq.setSubName(orchestrateRes.getSubName());
        showStuInfoReq.setType("stuReady");
        wsMessage.setMessage(JSON.toJSONString(showStuInfoReq));
        webSocketService.sendInfo(wsMessage);
        return AjaxResult.success();
    }

    @Override
    public AjaxResult getReadyStu() {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        String orchestrateResStr = redisCache.getCacheObject("selectAthlete:" + loginUser.getUser().getParentId());
        GetReadyStuRes getReadyStuRes = JSON.parseObject(orchestrateResStr, GetReadyStuRes.class);
        if (getReadyStuRes == null) {
            return AjaxResult.success(null);
        }

        BaseSubject baseSubject = baseSubjectMapper.selectById(getReadyStuRes.getSubId());

        LambdaQueryWrapper<BaseSubItem> baseSubItemLambdaQueryWrapper = new LambdaQueryWrapper<>();
        baseSubItemLambdaQueryWrapper.eq(BaseSubItem::getSubId, getReadyStuRes.getSubId());
        List<BaseSubItem> baseSubItemList = baseSubItemMapper.selectList(baseSubItemLambdaQueryWrapper);

        List<BaseSubItemWithOneScoreRes> baseSubItemWithOneScoreResList = new ArrayList<>();
        if (baseSubject.getCode().equals("dg") || baseSubject.getCode().equals("jq")) {
            LambdaQueryWrapper<BaseScore> baseScoreLambdaQueryWrapper = new LambdaQueryWrapper<>();
            baseScoreLambdaQueryWrapper.eq(BaseScore::getObjectType, getReadyStuRes.getObjectType());
            baseScoreLambdaQueryWrapper.eq(BaseScore::getObjectId, getReadyStuRes.getObjectId());
            baseScoreLambdaQueryWrapper.eq(BaseScore::getSubId, getReadyStuRes.getSubId());
            baseScoreLambdaQueryWrapper.eq(BaseScore::getCount, 1);
            List<BaseScore> baseScoreList = baseScoreMapper.selectList(baseScoreLambdaQueryWrapper);
            Map<Long, BaseScore> baseScoreMap = baseScoreList.stream().collect(Collectors.toMap(BaseScore::getItemNo, e1 -> e1));

            List<Long> postIds = postService.selectPostListByUserId(loginUser.getUserId());
            List<Long> itemNoList = new ArrayList<>();
            //D分裁判
            if (postIds.contains(11L)) {
                itemNoList.add(0L);
                itemNoList.add(1L);
                itemNoList.add(8L);
                itemNoList.add(9L);
            }
            //E1分裁判
            if (postIds.contains(12L)) {
                itemNoList.add(2L);
            }
            //E2分裁判
            if (postIds.contains(13L)) {
                itemNoList.add(3L);
            }
            //E3分裁判
            if (postIds.contains(14L)) {
                itemNoList.add(4L);
            }

            for (int i = 0; i < baseSubItemList.size(); i++) {
                BaseSubItem baseSubItem = baseSubItemList.get(i);
                if (!itemNoList.contains(baseSubItem.getItemNo())) {
                    continue;
                }
                BaseSubItemWithOneScoreRes baseSubItemWithOneScoreRes = new BaseSubItemWithOneScoreRes();
                BeanUtils.copyProperties(baseSubItem, baseSubItemWithOneScoreRes);
                baseSubItemWithOneScoreRes.setBaseScore(baseScoreMap.get(baseSubItemWithOneScoreRes.getItemNo()));
                baseSubItemWithOneScoreRes.setCount(1L);
                baseSubItemWithOneScoreResList.add(baseSubItemWithOneScoreRes);
            }
            getReadyStuRes.setBaseSubItemWithOneScoreResList(baseSubItemWithOneScoreResList);
        } else {
            long count = 0;
            //获取成绩
            LambdaQueryWrapper<BaseScore> baseScoreLambdaQueryWrapper = new LambdaQueryWrapper<>();
            SysDept sysDept = loginUser.getUser().getDept();
            List<Long> postIds = postService.selectPostListByUserId(loginUser.getUserId());
            if (postIds.contains(7L)) {
                baseScoreLambdaQueryWrapper.eq(BaseScore::getCount, 1);
                count = 1;
            }
            if (postIds.contains(9L)) {
                baseScoreLambdaQueryWrapper.eq(BaseScore::getCount, 2);
                count = 2;
            }
            if (postIds.contains(10L)) {
                baseScoreLambdaQueryWrapper.eq(BaseScore::getCount, 3);
                count = 3;
            }

            baseScoreLambdaQueryWrapper.eq(BaseScore::getObjectType, getReadyStuRes.getObjectType());
            baseScoreLambdaQueryWrapper.eq(BaseScore::getObjectId, getReadyStuRes.getObjectId());
            baseScoreLambdaQueryWrapper.eq(BaseScore::getSubId, getReadyStuRes.getSubId());
            baseScoreLambdaQueryWrapper.eq(BaseScore::getGroupId, getReadyStuRes.getGroupId());
            List<BaseScore> baseScoreList = baseScoreMapper.selectList(baseScoreLambdaQueryWrapper);
            Map<Long, BaseScore> baseScoreMap = baseScoreList.stream().collect(Collectors.toMap(BaseScore::getItemNo, e1 -> e1));

            for (int i = 0; i < baseSubItemList.size(); i++) {
                BaseSubItem baseSubItem = baseSubItemList.get(i);
                BaseSubItemWithOneScoreRes baseSubItemWithOneScoreRes = new BaseSubItemWithOneScoreRes();
                BeanUtils.copyProperties(baseSubItem, baseSubItemWithOneScoreRes);
                baseSubItemWithOneScoreRes.setBaseScore(baseScoreMap.get(baseSubItemWithOneScoreRes.getItemNo()));
                baseSubItemWithOneScoreRes.setCount(count);
                baseSubItemWithOneScoreResList.add(baseSubItemWithOneScoreRes);
            }
            getReadyStuRes.setBaseSubItemWithOneScoreResList(baseSubItemWithOneScoreResList);
        }

        return AjaxResult.success(getReadyStuRes);
    }

    @Override
    public String inputScoreExcel(List<OrchestrateWithSubRes> orchestrateWithSubRes, boolean updateSupport, String operName) {
        if (StringUtils.isNull(orchestrateWithSubRes) || orchestrateWithSubRes.size() == 0) {
            throw new ServiceException("导入学校数据不能为空！");
        }
        int successNum = 0;
        int failureNum = 0;
        StringBuilder successMsg = new StringBuilder();
        StringBuilder failureMsg = new StringBuilder();
        LoginUser loginUser = SecurityUtils.getLoginUser();
        Long raceId = loginUser.getSelectRaceId();
        for (OrchestrateWithSubRes orchestrate : orchestrateWithSubRes) {
            UpdateScoreReq updateScoreReq = new UpdateScoreReq();
            updateScoreReq.setRawScore(orchestrate.getInputScore());
            updateScoreReq.setCount(0L);
            updateScoreReq.setItemNo(0L);
            updateScoreReq.setObjectType(Math.toIntExact(orchestrate.getObjectType()));
            updateScoreReq.setObjectId(orchestrate.getObjectId());
            updateScoreReq.setSubId(orchestrate.getSubId());
            updateScoreReq.setGroupId(orchestrate.getGroupId());
            updateStuScore(updateScoreReq);
            successNum++;
        }
        if (failureNum > 0) {
            failureMsg.insert(0, "很抱歉，导入失败！共 " + failureNum + " 条数据格式不正确，错误如下：");
            throw new ServiceException(failureMsg.toString());
        } else {
            successMsg.insert(0, "恭喜您，数据已全部导入成功！共 " + successNum + " 条，数据如下：");
        }
        return successMsg.toString();
    }

    @Override
    public AjaxResult getAllLsmpZb() {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        List<Long> zbList = baseScoreMapper.getAllLsmpZb(loginUser.getSelectRaceId());
        return AjaxResult.success(zbList);
    }

    @Override
    public AjaxResult outputAllScoreExcel(HttpServletResponse response, Long groupId) throws IOException {
        AjaxResult ajaxResult = getSchoolScoreList(-1L, groupId);
        List<SchoolScoreRes> schoolScoreResList = (List<SchoolScoreRes>) ajaxResult.get(DATA_TAG);

        List<SubjectTree> subjectTrees = baseSubjectService.selectDeptTreeList(new BaseSubject());

        // 创建Excel工作簿对象
        Workbook wb = new XSSFWorkbook();
        // 创建单元格样式
        CellStyle style = wb.createCellStyle();
        style.setAlignment(HorizontalAlignment.CENTER); // 水平居中
        style.setVerticalAlignment(VerticalAlignment.CENTER); // 垂直居中
        // 创建边框
        style.setBorderTop(BorderStyle.THIN);
        style.setBorderBottom(BorderStyle.THIN);
        style.setBorderLeft(BorderStyle.THIN);
        style.setBorderRight(BorderStyle.THIN);

        // 创建第一个sheet页
        Sheet tuanDuiSheet = wb.createSheet("学校团体分汇总");

        // 在第一个sheet页中创建行和单元格
        Row row = tuanDuiSheet.createRow(0);
        Cell cell = row.createCell(0);
        cell.setCellValue("学校总分汇总表");

        // 设置行高：height = 磅 * 20 （1磅=0.353毫米=20缇）-> POI中行高是"缇(twips)"
        row.setHeight((short) (25 * 20));

        row = tuanDuiSheet.createRow(1);

        List<Long> outputSubList = new ArrayList<>();
        outputSubList.add(4L);
        outputSubList.add(5L);
        outputSubList.add(6L);
        outputSubList.add(7L);
        outputSubList.add(8L);
        outputSubList.add(9L);
        outputSubList.add(10L);

//        for (int i = 0; i < subjectTrees.size(); i++) {
//            for (int j = 0; j < subjectTrees.get(i).getChildren().size(); j++) {
//                tuanDuiSheet.getRow(2);
//                cell = row.createCell(subIndex++);
//                cell.setCellValue(subjectTrees.get(i).getChildren().get(j).getLabel());
//            }
//        }
        List<BaseSubject> baseSubjectList = new ArrayList<>();
        LambdaQueryWrapper<BaseSubject> baseSubjectLambdaQueryWrapper = new LambdaQueryWrapper<BaseSubject>();
        baseSubjectLambdaQueryWrapper.in(BaseSubject::getId, outputSubList);
        baseSubjectList = baseSubjectMapper.selectList(baseSubjectLambdaQueryWrapper);
        Map<Long, BaseSubject> baseSubjectMap = baseSubjectList.stream().collect(Collectors.toMap(BaseSubject::getId, e1 -> e1));
        int subIndex = 0;
        cell = row.createCell(subIndex++);
        cell.setCellValue("学校");
        for (int i = 0; i < baseSubjectList.size(); i++) {
            tuanDuiSheet.getRow(1);
            cell = row.createCell(subIndex++);
            cell.setCellValue(baseSubjectList.get(i).getName());
        }
        cell = row.createCell(subIndex++);
        cell.setCellValue("总分");
        cell = row.createCell(subIndex++);
        cell.setCellValue("名次");

        row = tuanDuiSheet.createRow(2);
        for (int i = 0; i < schoolScoreResList.size(); i++) {
            row = tuanDuiSheet.createRow(2 + i);
            SchoolScoreRes schoolScoreRes = schoolScoreResList.get(i);
            subIndex = 0;
            cell = row.createCell(subIndex++);
            cell.setCellValue(schoolScoreRes.getUnitName());
            for (int j = 0; j < outputSubList.size(); j++) {
                Long subId = outputSubList.get(j);
                cell = row.createCell(subIndex++);
                for (int k = 0; k < schoolScoreRes.getScoreItemList().size(); k++) {
                    SchoolScoreRes.ScoreItem scoreItem = getScore(schoolScoreRes.getScoreItemList().get(k), subId);

                    if (scoreItem != null) {
                        cell.setCellValue(Double.parseDouble(scoreItem.getScore()));
                    }
                }

            }
            cell = row.createCell(subIndex++);
            cell.setCellValue(schoolScoreRes.getScore());
            cell = row.createCell(subIndex++);
            cell.setCellValue(schoolScoreRes.getMc());
        }


        // 导出Excel文件
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setCharacterEncoding("utf-8");
        wb.write(response.getOutputStream());
        wb.close();
        return null;
    }


    @Override
    public AjaxResult getBigScreenData(Long groupId) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("schoolTotalNum", 16);
        jsonObject.put("stuTotalNum", 282);
        AjaxResult ajaxResult = getSchoolScoreList(-1L, groupId);
//        AjaxResult ajaxResult2 = getStudentScoreList(-1L);
        List<SchoolScoreRes> schoolScoreResList = (List<SchoolScoreRes>) ajaxResult.get(DATA_TAG);
//        List<SchoolScoreRes> stuScoreResList = (List<SchoolScoreRes>) ajaxResult2.get(DATA_TAG);
        jsonObject.put("schoolScoreResList", schoolScoreResList);
        jsonObject.put("stuScoreResList", new ArrayList<>());
        jsonObject.put("bigScreenScoreResArrayList", bigScreenScoreResArrayList);
        List<BigScreenBaseSubjectItem> bigScreenBaseSubjectItems = new ArrayList<>();

        Map<Long, SchoolScoreRes> schoolScoreResMap = schoolScoreResList.stream().collect(Collectors.toMap(SchoolScoreRes::getId, e -> e));

//        List<Long> subIdList =
        List<BaseSubject> baseSubjectList = baseSubjectService.selectBaseSubjectList(new BaseSubject());
        Map<Long, BaseSubject> baseSubjectMap = baseSubjectList.stream().collect(Collectors.toMap(BaseSubject::getId, e1 -> e1));

        Long[] subList = new Long[]{7L, 9L, 10L, 8L, 4L, 5L, 6L};
        List<BaseSubject> subjectList = new ArrayList<>();
        LambdaQueryWrapper<BaseSubject> baseSubjectLambdaQueryWrapper = new LambdaQueryWrapper<>();
        baseSubjectLambdaQueryWrapper.in(BaseSubject::getId, subList);
        subjectList = baseSubjectMapper.selectList(baseSubjectLambdaQueryWrapper);
        for (int i = 0; i < subList.length; i++) {
            BigScreenBaseSubjectItem bigScreenBaseSubjectItem = new BigScreenBaseSubjectItem();
            BaseSubject baseSubject = subjectList.get(i);
            BeanUtils.copyProperties(baseSubject, bigScreenBaseSubjectItem);

//            if (baseSubject.getLottery() != null && baseSubject.getLottery() == 1) {
//                System.out.println("");
//                List<BaseSubject> childSubjectList = new ArrayList<>();
//                LambdaQueryWrapper<BaseSubject> childBaseSubjectLambdaQueryWrapper = new LambdaQueryWrapper<>();
//                childBaseSubjectLambdaQueryWrapper.eq(BaseSubject::getParentId, baseSubject.getParentId());
//                childSubjectList = baseSubjectMapper.selectList(childBaseSubjectLambdaQueryWrapper);
//                //一定是个人项目：:
//
//            } else {
//                if (baseSubject.getType() == 1) {
//                    System.out.println("");
//                }
//                if (baseSubject.getType() == 2) {
//                    System.out.println("");
//                }
//            }
            List<BigScreenBaseSubjectItem.BigScreenSchoolSubItem> bigScreenSchoolSubItems = new ArrayList<>();
            for (int j = 0; j < schoolScoreResList.size(); j++) {
                BigScreenBaseSubjectItem.BigScreenSchoolSubItem bigScreenSchoolSubItem = new BigScreenBaseSubjectItem.BigScreenSchoolSubItem();
                bigScreenSchoolSubItem.setSchoolName(schoolScoreResList.get(j).getUnitName());
                for (int k = 0; k < schoolScoreResList.get(j).getScoreItemList().size(); k++) {
                    SchoolScoreRes.ScoreItem scoreItem = getScore(schoolScoreResList.get(j).getScoreItemList().get(k), bigScreenBaseSubjectItem.getId());
                    if (scoreItem != null) {
                        bigScreenSchoolSubItem.setScore(scoreItem.getScore());
                    }
                }

                bigScreenSchoolSubItems.add(bigScreenSchoolSubItem);

            }
            bigScreenBaseSubjectItem.setBigScreenSchoolSubItems(bigScreenSchoolSubItems);
            bigScreenBaseSubjectItems.add(bigScreenBaseSubjectItem);
        }
        jsonObject.put("bigScreenBaseSubjectItems", bigScreenBaseSubjectItems);
        return AjaxResult.success(jsonObject);
    }


    public SchoolScoreRes.ScoreItem getScore(SchoolScoreRes.ScoreItem root, Long id) {
        if (root == null) {
            return null;
        }
        if (root.getSubId() == id) {
            return root;
        }
        if (root.getChildScoreItemList() == null) {
            return null;
        }
        for (SchoolScoreRes.ScoreItem child : root.getChildScoreItemList()) {
            SchoolScoreRes.ScoreItem found = getScore(child, id);
            if (found != null) {
                return found;
            }
        }
        return null;
    }

    @Override
    public AjaxResult getScoreBigScreen(Long subId, Long groupId) {
        GetScoreItemReq getScoreItemReq = new GetScoreItemReq();
        getScoreItemReq.setSubId(subId);
        getScoreItemReq.setGroupId(groupId);
        TableDataInfo tableDataInfo = getScoreItem(getScoreItemReq, 1, 1000);
        List<OrchestrateWithSubRes> orchestrateWithSubResList = (List<OrchestrateWithSubRes>) tableDataInfo.getRows();

        return AjaxResult.success(orchestrateWithSubResList);
    }
}
